﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using ScrappyDB.Linq;

namespace ScrappyDB.IntegrationTests.AwsQuery101Examples
{
    [TestFixture]
    public class CountingTests
    {
        /************************************************************************************
        * Example SQL:          select count(*) from mydomain where Title = 'The Right Stuff' 	
        * Description:          Counts all items where the attribute "Title" equals "The Right Stuff." 	
        * Expected result:      1 
        ************************************************************************************/
        [Test]
        public void EqualsCountTest()
        {
            var dbContext = new AwsSampleContext();
            var count = dbContext.Books.Count(a => a.Title == "The Right Stuff");

            Assert.AreEqual(1, count);
        }

        /************************************************************************************
        * Example SQL:          select count(*) from mydomain where Year > '1985' 	
        * Description:          Counts all items where "Year" is greater than "1985."  	
        * Expected result:      3 
        ************************************************************************************/
        [Test]
        public void GreaterThanCountTest()
        {
            var dbContext = new AwsSampleContext();
            var count = dbContext.Books.Count(a => a.Year.GreaterThan( "1985"));

            Assert.AreEqual(3, count);
        }

        [Test]
        public void GreaterThanNumericCountTest()
        {
            var dbContext = new AwsSampleContext();
            var count = dbContext.Books.Count(a => a.YearInt > 1985);

            Assert.AreEqual(3, count);
        }

        /************************************************************************************
        * Example SQL:          select count(*) from mydomain limit 500 	
        * Description:          Counts all items in the domain, with a limit of 500. 	
        * Expected result:      6 
        ************************************************************************************/
        [Test]
        public void LimitCountTest()
        {
            var dbContext = new AwsSampleContext();
            var count = (from a in dbContext.Books select a).Take(500).Count();
            Assert.AreEqual(6, count);
        }

        /************************************************************************************
        * Example SQL:          select count(*) from mydomain limit 4 	
        * Description:          Counts all items in the domain, with a limit of 4. 	
        * Expected result:      4 
        ************************************************************************************/
        [Test]
        public void LimitCountTest2()
        {
            var dbContext = new AwsSampleContext();
            var count = (from a in dbContext.Books select a).Take(4).Count();
            Assert.AreEqual(4, count);
        }


    }
}
